package array;

/**
 * @author way
 * @create 2025-02-04 10:56
 *
 * https://leetcode.cn/problems/squares-of-a-sorted-array/
 */
public class _977_sortedSquares {
    public int[] sortedSquares(int[] nums) {
        int[] res = new int[nums.length];
        int l = 0;
        int r = nums.length-1;
        int i = nums.length-1;
        while (l<=r){
            if (nums[l]*nums[l]>nums[r]*nums[r]){
                res[i] = nums[l]*nums[l];
                l++;
                i--;
            }else {
                res[i]  = nums[r]*nums[r];
                r--;
                i--;
            }
        }
        return res;
    }
}
